#ifndef GRAPH_H
#define GRAPH_H

#include <QDebug>
#include <QVector>
#include <QHash>
#include <QGraphicsObject>
#include <QtGui>

#include <vtkSmartPointer.h>
#include <vtkMutableDirectedGraph.h>
#include <vtkForceDirectedLayoutStrategy.h>
#include <vtkGraphLayout.h>
#include <vtkVertexListIterator.h>

class Node;
class Edge;
class QualAttributeSet;
class QualAttribute;

class Graph : public QGraphicsObject
{
    Q_OBJECT
public:
    Graph(QGraphicsWidget *p = 0);
    ~Graph();
    Graph( const Graph& copy );

    bool addEdge( QString node1, QString node2, QString interactionType);
    void itemMoved();
    void applyForceDirectedLayout();

    void forgeConnection( Graph* other );
    void forgeConnection( QualAttributeSet attSet);

    void addAttribute(QPointer<QualAttribute> att);

protected:
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    QGraphicsWidget* parent;

    void addConnection(QString nodeName, Node* node);

private:
    QVector<Node*> nodes;
    QVector<Edge*> edges;
    QHash<QString, short> nodeNameToNodeIdx;//save memory by hashing to idx
    QHash<QString, short> edgeNameToEdgeIdx;
    vtkSmartPointer<vtkMutableDirectedGraph> vtkGraph;
};

#endif // GRAPH_H
